<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
    
	//
    // t_field_checkbox
    //
	class t_field_checkbox extends t_base_field
	{
        
        // property declaration
		// protected

        // L
        //protected $value_db_fields = array();
        protected $label_tag = null;
		// M
		protected $message_tag = null;		
      

        // property declaration
		// public
		// G
		const language_position_per_can_not_be_empty = 1;
		const language_position_last = 2;
		// P
        const proper_properties_position_per_NULL = 1;
        const proper_properties_position_per_label = 2;        
        const proper_properties_position_last = 3;
        // method declaration
    	// protected
		// A
		protected function adds_check_value_method()
        {
            global $g_javascript_namespace;
         	$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"check_value","a_name","
    var local_name = a_name;
	if (a_name == undefined)
		local_name = this.name;                
    var local_value = this.html_tag(local_name).value.trim();            
    var local_msg_tag = this.html_tag(local_name+'_msg');           
	var local_return = true;
    if (this.can_not_be_empty)
    {
		local_return = (this.html_tag(this.name).value.trim() != '');
		
    }
    if (!local_return)
        local_msg_tag.innerHTML = this.can_not_be_empty_msg;
    else
        local_msg_tag.innerHTML = '';    
	return local_return;
    "); 
        }

        // G
		protected function get_field_event_script($a_event_type,$a_argouments)
        {			
			$local_return = '';
			return $local_return;
		}
static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = 'TRUE';
				break;                
			}*/
			return $local_return;
		}
		protected function get_proper_properties_position_last()      
		{
            return self::proper_properties_position_last;
        }
		
        // method declaration
    	// public
        public function __construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str)
		{
            parent::__construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str);
            
			
		}

		// C
		public function create_javascript_initialization_component()
		{
		
		}
		public function create_tags_structure()
        {
            //echo __METHOD__."<BR>";
			global $g_javascript_namespace;
            if (($this->proper_properties_array[self::proper_properties_position_per_NULL] == 1) ||
                (strtoupper($this->proper_properties_array[self::proper_properties_position_per_NULL]) == "TRUE"))
                $local_can_not_be_empty = "true";
            else
                $local_can_not_be_empty = "false";
			$local_can_not_be_empty_msg = addslashes($this->lang[self::language_position_per_can_not_be_empty]);	
            parent::create_tags_structure(
				// ARGUMENTS DECLARATIONS
                "a_can_not_be_empty,a_can_not_be_empty_msg",
                // ARGUMENTS VALUES
                "$local_can_not_be_empty,'$local_can_not_be_empty_msg'");
			// proprierties

			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'can_not_be_empty',"a_can_not_be_empty",false);
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'can_not_be_empty_msg',"a_can_not_be_empty_msg",false);	

            $local_name = $this->common_properties_array[t_base_field::common_properties_position_per_field_name];
            $local_label = $this->proper_properties_array[self::proper_properties_position_per_label];
            if (trim($local_label) != '')
            {
                $local_current_tag = parent::add_tag(t_base_tag_type::btt_label,$local_name . "_label");
                $this->label_tag = $local_current_tag;
				$local_current_tag->set_text_to_include($local_label);
            }    
             
            $local_current_tag = parent::add_tag(t_base_tag_type::btt_checkbox,
                $local_name);
			$this->main_tag = $local_current_tag;
            $this->default_start_tag = $this->main_tag;
            $this->default_result_tag = $this->main_tag;
			// message tag
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_label,$local_name . "_msg");
            $this->message_tag = $local_current_tag;
			$this->message_tag->class_name = t_base_field::error_msg_class_name;	
            // method
            $this->adds_check_value_method();

            
        }
        // G
		public function get_included_in_html_structure($a_name,$a_display,$a_key_tag_name)
		{
			//parent::get_included_in_html_structure($a_name);
			if ($a_display)
			{
				if (isset($this->label_tag))
					$this->label_tag->add_style_property('display','');
				$this->main_tag->add_style_property('display','');
				$this->message_tag->add_style_property('display','');
			}
			else
			{
				if (isset($this->label_tag))
					$this->label_tag->add_style_property('display','none');			
				$this->main_tag->add_style_property('display','none');
				$this->message_tag->add_style_property('display','none');
			}	
			$this->main_tag->remove_property('disabled');
			
			$this->key_tags_list[$a_name] = $a_key_tag_name;
			//echo "a_name: $a_name - a_key_tag_name: $a_key_tag_name<br>";
			$local_label_script = '';
			if (isset($this->label_tag))
				$local_label_script = $this->label_tag->generate_html_code_with_new_name($a_name.t_field_text::postfix_label_tag_name);
			return $local_label_script .
				($this->main_tag->generate_html_code_with_new_name($a_name) .
				$this->message_tag->generate_html_code_with_new_name($a_name.t_field_text::postfix_message_tag_name));
		}
		
		public function get_included_in_html_structure_no_edit_mode($a_id,$a_value,$a_label_value)
		{
			
			if (isset($this->label_tag))
				$this->label_tag->add_style_property('display','');			
			$this->main_tag->add_style_property('display','');
			$this->message_tag->add_style_property('display','');
			//echo "a_value: $a_value<br>";
			if ($a_value == 1) 
			{
				
				$this->main_tag->add_property('checked','checked');
			}
			else	
				$this->main_tag->remove_property('checked');
			$this->main_tag->add_property('disabled','disabled');	
			$local_label_script = '';
			if (isset($this->label_tag))
				$local_label_script = $this->label_tag->generate_html_code_with_new_name($a_id.t_field_text::postfix_label_tag_name);
			return $local_label_script .
				($this->main_tag->generate_html_code_with_new_name($a_id));
			
			
		}
		
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		public function get_result_action_script($a_event_type,$parent_event_type,
            $a_parameter,$a_content_loader_result)
		{
            return '';
        }		
		
        // I
		public function initialize_field_event($a_event_type)
        {			
			
		}
        
       

		

    }
?>    